#include "ofxIRCMessageFactory.h"
#include "ofxIRCMessageType.h"
#include "ofxIRCPrivMsg.h"

#include <iostream>

ofxIRCMessageFactory::ofxIRCMessageFactory() {
}

ofxIRCMessageType* ofxIRCMessageFactory::parse(std::string sRaw) {
	if (sRaw.size() == 0) return NULL;

	// parse on ':'
	// ------------------------------------------------------------------
	char split_char = ':';
	std::vector<std::string> tokens;
	std::istringstream split(sRaw);
	for(std::string each;
		std::getline(split, each, split_char);
		tokens.push_back(each));

	// message like: ":user!n=user@80-232-23-32.xsdf.com PRIVMSG #jobjob :message"
	// ------------------------------------------------------------------
	split_char = ' ';
	std::vector<std::string> params;
	std::istringstream param_data(tokens.at(1));

	// get parameters, so we know the 'type' of command.
	for(std::string each;
		std::getline(param_data, each, split_char);
		params.push_back(each));

	if (params.size() == 0) {
		return NULL;
	}

	if(params.size() >= 2
		&& params.at(1).find("PRIVMSG") != std::string::npos)
	{
		return new ofxIRCPrivMsg(CMD_PRIVMSG,tokens, params);
	}
	else if(params.at(0).find("PING") != std::string::npos) {

	}


	return NULL;
}

